package com.http.controller;

import com.http.config.Result;
import com.http.pojo.User;
import com.http.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @ClassName: OkHttpController
 * @Description: OkHttp操作接口
 * @author: QT
 * @date: 2021年06月06日 下午11:17:59
 */
@Api(tags = "OkHttpController", description = "OkHttp操作接口")
@RestController
@RequestMapping("/okhttp")
public class OkHttpController {
    public static final Logger log = LoggerFactory.getLogger(OkHttpController.class);

    @Autowired
    UserService userService;

    @ApiOperation("按员工ID获取员工列表")
    @GetMapping("/queryUserById/{id}")
    public @ResponseBody
    Result queryUserById(@ApiParam(name = "id", value = "用户ID", required = true)
                         @PathVariable int id) throws IOException {
        String user = userService.getUserById(id);
        return Result.succResult(user);
    }

    @ApiOperation("员工修改")
    @PostMapping("/updateUser/{id}")
    public @ResponseBody
    Result updateUserResult(
            @ApiParam(value = "用户ID", required = true) @PathVariable Integer id,
            @ApiParam(value = "Token", required = true) @RequestHeader String token,
            @ApiParam(value = "用户信息", required = true)  @RequestBody User user) throws IOException {
        String object = userService.updateUser(id,token,user);
        return Result.succResult(object);
    }

    @ApiOperation("员工新增")
    @PostMapping("/createUser")
    public @ResponseBody
    Result createUserResult(@ApiParam(value = "用户信息", required = true) @RequestBody User user) throws IOException {
        String object = userService.createUser(user);
        return Result.succResult(object);
    }


}
